package cn.esale.service.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import cn.esale.dao.CommonDao;
import cn.esale.entity.SaleOrder;
import cn.esale.entity.SaleOrderLine;
import cn.esale.service.OrderBiz;

@Service("orderBiz")
public class OrderBizImpl implements OrderBiz{
	@Autowired
	@Qualifier("commonDao")
	private CommonDao commonDao;
	
	public void add(SaleOrder saleOrder) {
		// TODO Auto-generated method stub
		this.commonDao.add(saleOrder);
		
	}

	public SaleOrder get(Serializable id) {
		// TODO Auto-generated method stub
		SaleOrder ret = (SaleOrder) this.commonDao.get(SaleOrder.class, id);
		return ret;
	}

	public SaleOrder getWithLines(Serializable id) {
		// TODO Auto-generated method stub
		SaleOrder ret = null;
		String hql ="select o from SaleOrder o left join fetch"
				+" o.saleOrderLines where o.odrId="+id;
		List list = this.commonDao.search(hql);
		if(null != list &&  !list.isEmpty()){
			ret = (SaleOrder) list.get(0);
		}
		return ret;
	}

	public void addDetail(SaleOrderLine orderDetail) {
		// TODO Auto-generated method stub
		this.commonDao.add(orderDetail);
	}

}
